
#include "thread.h"
#include <stdio.h>
#include <stdlib.h>
int b=0;
long int m=1;
int c=0;
void* func(void* i){
	thread_t thread1;
	b++;
	if(b>m)
		return NULL;
	c++;
	if(c>1000)
		c=0;
		fprintf(stderr,"Now with %ld thread",b);
	thread_create(&thread1,func,NULL);
	thread_join(thread1,NULL);
	return NULL;
}
void* junc(void* i){
	return NULL;
}
void* kunc(void* i){
	thread_yield();
	fprintf(stderr,"exiting thread\n");
	return NULL;
}
int main(int argc,char* argv[]){
	m= argc>1 ? atoi(argv[1]) : 30000;

	fprintf(stdout,"Starting test with %d threads\n", m);
	thread_t thread;
	thread_create(&thread,kunc,NULL);
	thread_join(thread,NULL);

	return 0;
}
